#include <stdio.h>
#include <string.h>
#include "initProgram.h"
#include "saveFile.h"
int saveFile(int identity)
{
	char str[256] = {};
	if(2 == identity || 1 == identity)
	{
		//写入学生信息
		FILE* stuFwp = fopen("stuList.txt","w");
		if(NULL == stuFwp)
		{
			perror("stuFwp");
			return 1;
		}
		for(int i = 0; i < STUMAX; i++)
		{
			if(student[i].id)
			{
				sprintf(str,"%s %s %.1lf %.1lf %.1lf %d %c %hhd\n",student[i].name,student[i].password,student[i].chnScore,student[i].mathScore,student[i].engScore,student[i].id,student[i].sex,student[i].flag);
				fputs(str,stuFwp);
			}
		}
		fclose(stuFwp);
		stuFwp = NULL;
	}
	if(3 == identity)
	{
		//写入教师信息
		FILE* tchFwp = fopen("tchList.txt","w");
		if(NULL == tchFwp)
		{
			perror("tchFwp");
			return 1;
		}
		for(int i = 0; i < TCHMAX; i++)
		{
			if(teacher[i].id)
			{
				sprintf(str,"%s %s %d %c %hhd\n",teacher[i].name,teacher[i].password,teacher[i].id,teacher[i].sex,teacher[i].flag);
				fputs(str,tchFwp);
			}
		}
		fclose(tchFwp);
		tchFwp = NULL;
	}
	return 0;
}
